package pl.dsp.dsp1.ui;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.EmptyBorder;

public class RadarWindow extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6154460137324525318L;

	private JPanel graphContainer1, graphContainer2, graphContainer3;

	public JPanel getGraphContainer1() {
		return graphContainer1;
	}

	public JPanel getGraphContainer2() {
		return graphContainer2;
	}

	public JPanel getGraphContainer3() {
		return graphContainer3;
	}

	private JSpinner objectDistanceSpinner, signalSpeedSpinner, tSpinner,
			fpSpinner, bufferSizeSpinner, refreshTimeSpinner;
	private JLabel resultLabel;

	public JLabel getResultLabel() {
		return resultLabel;
	}

	public double getObjectDistance() {
		return (Double) objectDistanceSpinner.getModel().getValue();
	}

	public double getSignalSpeed() {
		return (Double) signalSpeedSpinner.getModel().getValue();
	}

	public double getT() {
		return (Double) tSpinner.getModel().getValue();
	}

	public double getFp() {
		return (Double) fpSpinner.getModel().getValue();
	}

	public int getBufferSize() {
		return (Integer) bufferSizeSpinner.getModel().getValue();
	}

	public double getRefreshTime() {
		return (Double) refreshTimeSpinner.getModel().getValue();
	}

	public RadarWindow(MainWindow owner, WindowController controller) {
		super(owner, "Radar toolbox");
		controller.setRadarWindow(this);
		setResizable(false);
		setBounds(500, 50, 600, 620);

		JPanel contentPane = new JPanel();
		setContentPane(contentPane);
		contentPane.setBorder(new EmptyBorder(6, 6, 6, 6));
		contentPane.setLayout(new BorderLayout());

		JPanel graphsPanel = new JPanel(new GridLayout(3, 1));
		contentPane.add(graphsPanel, BorderLayout.CENTER);
		graphContainer1 = new JPanel();
		graphsPanel.add(graphContainer1);
		graphContainer2 = new JPanel();
		graphsPanel.add(graphContainer2);
		graphContainer3 = new JPanel();
		graphsPanel.add(graphContainer3);

		JPanel controlBar = new JPanel();
		controlBar.setLayout(new GridLayout(0, 2));
		contentPane.add(controlBar, BorderLayout.SOUTH);

		JButton startButton = new JButton("Start");
		startButton.addActionListener(controller);
		controlBar.add(startButton);

		JButton stopButton = new JButton("Stop");
		stopButton.addActionListener(controller);
		controlBar.add(stopButton);

		controlBar.add(new JLabel("Object distance (m):"));
		objectDistanceSpinner = new JSpinner();
		objectDistanceSpinner.setModel(new SpinnerNumberModel(new Double(2), null,
				null, new Double(1)));
		controlBar.add(objectDistanceSpinner);

		controlBar.add(new JLabel("Signal speed (m/s):"));
		signalSpeedSpinner = new JSpinner();
		signalSpeedSpinner.setModel(new SpinnerNumberModel(new Double(20), null,
				null, new Double(1)));
		controlBar.add(signalSpeedSpinner);

		controlBar.add(new JLabel("T (s):"));
		tSpinner = new JSpinner();
		tSpinner.setModel(new SpinnerNumberModel(new Double(1), null, null,
				new Double(1)));
		controlBar.add(tSpinner);

		controlBar.add(new JLabel("Fp (Hz):"));
		fpSpinner = new JSpinner();
		fpSpinner.setModel(new SpinnerNumberModel(new Double(60), null, null,
				new Double(1)));
		controlBar.add(fpSpinner);

		controlBar.add(new JLabel("Buffer size:"));
		bufferSizeSpinner = new JSpinner();
		bufferSizeSpinner.setModel(new SpinnerNumberModel(new Integer(150), null,
				null, new Integer(1)));
		controlBar.add(bufferSizeSpinner);

		controlBar.add(new JLabel("Refresh time (s):"));
		refreshTimeSpinner = new JSpinner();
		refreshTimeSpinner.setModel(new SpinnerNumberModel(new Double(0.2), null,
				null, new Double(1)));
		controlBar.add(refreshTimeSpinner);

		resultLabel = new JLabel("Distance:");
		controlBar.add(resultLabel);
	}
}
